<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title>预约项目</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
<!-- <div class="box box-primary" id="more" style="width:110px;height:40px;background-color:#222c32;position:absolute;z-index:9999;left:850px;top:100px;display:none;font-size:12px;border-top-color:#222c32;">
            <div class="box-header with-border">
                	更多操作
            </div> --><!-- /.box-header
            <div class="box-body home-message" id="moreOp">
            </div>
        </div> -->
    <section class="content-header">
        <h1>预约管理</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active">药品招标管理</li>
            <li class="active">预约管理</li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                    <div class="form-group form-group-xs">
                         <label>项目名称：</label>
                         <select class="form-control" style="width:220px;" id="projId" name="projId"></select>
                    </div>
                   
                    <button type="button" onclick="gridSerch()" class="btn btn-success btn-sm">查&nbsp;询</button>
                </div>
            </div>
        </div>

        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>

	<form action="${ctx}/bidSubscribe/toCenterSubscribeJsp.html" method="post" id="Form">
	<input type="hidden" id="projIdForm" name="projId">
	<input type="hidden" id="projName" name="projName">
	<input type="hidden" id="startTime" name="startTime">
	<input type="hidden" id="endTime" name="endTime">
	</form>
	<form action="${ctx}/bidSubscribe/toCompRecordJsp.html" method="post" id="recordForm">
	<input type="hidden" id="projIdRecord" name="projId">
	<input type="hidden" id="projNameRecord" name="projName">
	<input type="hidden" id="bidSubscribeId" name="bidSubscribeId">
	</form>
	<div id='coverdiv' style="Opacity:0.8;  position:fixed; left:0px; top:0px;width:100%;height:100%;"> </div>
        <div id='mydiv' style="border:0px solid #666666 ; padding:50px;text-align:center; position:absolute;background-image: url('${ctx }/lib/img/loading.gif'); background-repeat: no-repeat;">
</div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
    
    var cover =mydiv= null;
	window.onload = function() {
	  cover=document.getElementById('coverdiv');
	  cover.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
	  cover.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px"
	  cover.style.display = "none";
	 
	  mydiv = document.getElementById('mydiv');
	  with (mydiv){
	    style.width = document.documentElement.scrollHeight/2+"px";
	    style.height = document.documentElement.scrollHeight/2+"px";
	    style.left = (document.documentElement.scrollWidth - mydiv.offsetWidth)/2+"px";
	    style.top = (document.documentElement.scrollHeight - mydiv.offsetHeight)/2+"px";
	 
	    style.display = "none";
	  }
	};
        $(function () {
             	$("#projId").HNSelect({
                     url: "${pageContext.request.contextPath}/selectController/getDicBidCompany.html", data: { ID: '' }, defaultText: "<option value=''>请选择</option>",
                 });
            $("#gridlist").jqGrid({
                url: "${ctx}/bidSubscribe/getSetSubProjData.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['操作','projId', '项目编号', '项目名称','预约开始日期','预约结束日期','状态','现场确认地址'],
                colModel: [
                           { name: 'operate', width: 70,sortable: false, align:"left",
                           	formatter : function(val, opts, rowdata) {
                           		if (rowdata.isEnable == 0){
                           			return "<a href='javascript:void(0)' onclick=\"updateIsEnable('"+rowdata.bidSubscribeId+"','1')\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -140px -40px' class='opIcon' title='开启'></a>"
                           			+ "<a href='${ctx}/bidSubscribe/toSubscribeEditJsp.html?bidSubscribeId="+rowdata.bidSubscribeId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='编辑'></a>";
                           		}
                           		if(rowdata.isEnable == 1){
                           			return "<a href=\"javascript:close('"+rowdata.bidSubscribeId+"',2,'"+rowdata.isEnable+"')\"  style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -160px -20px' class='opIcon' title='关闭'></a>" 
                           				+"<a href='${ctx}/bidSubscribe/toSubscribeDetailJsp.html?bidSubscribeId="+rowdata.bidSubscribeId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -100px 0px' class='opIcon' title='详情'></a>"
                   					+"<a href=\"javascript:look('"+rowdata.projId+"','"+rowdata.projName+"','"+rowdata.bidSubscribeId+"');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -180px -20px' class='opIcon' title='预约情况查看'></a>";
                           		}
                           		if(rowdata.isEnable == 2){
                           			return "<a href='${ctx}/bidSubscribe/toSubscribeDetailJsp.html?bidSubscribeId="+rowdata.bidSubscribeId+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -100px 0px' class='opIcon' title='详情'></a>"
               					     +"<a href=\"javascript:look('"+rowdata.projId+"','"+rowdata.projName+"','"+rowdata.bidSubscribeId+"');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -180px -20px' class='opIcon' title='预约情况查看'></a>";
                           		}
                           		if (rowdata.isEnable == null || "" == rowdata.isEnable){
                           			return "<a href='javascript:void(0)' onclick=\"setDate('"+rowdata.projId+"','"+rowdata.projName+"','1','"+rowdata.projStarttime+"','"+rowdata.projEndtime+"')\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -60px -20px' class='opIcon' title='设置'></a>";
                           		}
                           	}	
                           },
                    { name: 'projId', key:true,hidden:true,width: 40, align: 'center' ,sortable: false},
                    { name: 'projCode', width: 140, align: 'center' ,sortable: false},
                    { name: 'projName', width: 130, align: 'center' ,sortable: false},
                    { name: 'subStartDate', width: 120, align: 'center' ,sortable: false},
                    { name: 'subEndDate', width: 120, align: 'center' ,sortable: false},
                    { name : 'isEnable', width : 80, align : 'center', sortable : false,
							formatter : function(val, opts,rowdata) {
								if (val == 1) {
									return "开启中";
								} 
								if (val == 0) {
									return "新建";
								}
								if (val == 2) {
									return "已关闭";
								}
								if(val == null || "" == val){
									return "待设置";
								}
					}},
					  { name : 'centerAddress', width : 160, align : 'center', sortable : false}
                    
                ],
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
                multiselect: false, 
                caption: "预约项目列表",
                jsonReader: {
                    repeatitems: false  
                },
                loadComplete: function (data) { //完成服务器请求后，回调函数
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
            //moreNoMore();
        });
        //查询
        function gridSerch() {
        	var projCode = $("#projCode").val();
        	var name = $("#name").val();
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{
    	        		"projCode":projCode,
    	        		"name":name}
    	    }).trigger("reloadGrid"); //重新载入  
    	}
      function updateIsEnable(bidSubscribeId,obj){
    	  $.HN.message
 			.confirm('确定开启预约吗？', '', '')
 			.on(
 					function(e) {
 						if (e) {
 							 mydiv.style.display =cover.style.display = '';
 							$.ajax({
 										type : "POST",
 										url : "${ctx}/bidSubscribe/startIsEnable.html",
 										data : "bidSubscribeId="
 												+ bidSubscribeId
 												+ "&isEnable="+obj,
 										dataType:"json",
 										success : function(result) {
 											if(result.success){
 												$.HN.message.alert('操作成功！','信息', 'success');
 												mydiv.style.display =cover.style.display = 'none';
 												gridSerch();
 											}else{
 												$.HN.message.alert('操作失败！','信息', 'error');
 											}
 										}
 									});
 						}
 					});
      }	

      //查询
      function gridSerch() {
          var projId = $("#projId").val();
          $("#gridlist").jqGrid('setGridParam',{  
              datatype:'json',
              postData:{"projId":projId}
          }).trigger("reloadGrid"); //重新载入  
      }
        
       //设置
        function setDate(id,name,status,startTime,endTime) {
    	   $("#projIdForm").val(id);
    	   $("#projName").val(name);
    	   $("#startTime").val(startTime);
    	   $("#endTime").val(endTime);
           $("#Form").submit();
    	} 
      
       function close(bidSubscribeId,obj,isEnable){
    	   var msgStr = obj == 1?'开启':'关闭';
    	   if(isEnable != 0){
    		   $.HN.message
   			.confirm('确定'+msgStr+'预约吗？', '', '')
   			.on(
   					function(e) {
   						if (e) {
   							$.ajax({
   										type : "POST",
   										url : "${ctx}/bidSubscribe/toSubscribeStatusUpdate.html",
   										data : "bidSubscribeId="
   												+ bidSubscribeId+","
   												+ "&isEnable="+obj,
   										dataType:"json",
   										success : function(result) {
   											if(result.success){
   												$.HN.message.alert('操作成功！','信息', 'success');
   												gridSerch();
   											}else{
   												$.HN.message.alert('操作失败！','信息', 'error');
   											}
   										}
   									});
   						}
   					});
    	   }
    		
       }

       function look(id,name,subId){
    	   $("#projIdRecord").val(id);
    	   $("#projNameRecord").val(name);
    	   $("#bidSubscribeId").val(subId);
    	   $("#recordForm").submit();
       }
    </script>
</body>
</html>